###
# This software is provided 'as-is', without any express or implied
# warranty.  In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
# 
# 1. The origin of this software must not be misrepresented; you must not
#    claim that you wrote the original software. If you use this software
#    in a product, an acknowledgment in the product documentation would be
#    appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
#    misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
#
# Note: Some of the libraries GMEngine may link to may have additional
# requirements or restrictions.
#
###

cmake_minimum_required(VERSION 2.8)

set(NAME TrefallRL)
project(${NAME})

set(RESOURCE_DIR ${CMAKE_SOURCE_DIR}/bin/Resources)
set(DEPENDENCY_DIR ${CMAKE_SOURCE_DIR}/depends)

file(GLOB VIEWS_RESOURCE ${RESOURCE_DIR}/Views/*.view)

file(GLOB_RECURSE LIBTCOD_HEADER_H ${DEPENDENCY_DIR}/libtcod/*.h)
file(GLOB_RECURSE LIBTCOD_HEADER ${DEPENDENCY_DIR}/libtcod/*.hpp)
file(GLOB_RECURSE LIBTCOD_SOURCE_C ${DEPENDENCY_DIR}/libtcod/*.c)
file(GLOB_RECURSE LIBTCOD_SOURCE ${DEPENDENCY_DIR}/libtcod/*.cpp)

file(GLOB_RECURSE TOTEM_HEADER ${DEPENDENCY_DIR}/Totem/*.h)
file(GLOB_RECURSE GLM_HEADER ${DEPENDENCY_DIR}/glm/*.hpp)
file(GLOB_RECURSE ZLIB_HEADER ${DEPENDENCY_DIR}/zlib-1.2.7/src/*.h)
file(GLOB_RECURSE PNG_HEADER ${DEPENDENCY_DIR}/libpng-1.5.10/src/*.h)
file(GLOB_RECURSE SDL_HEADER_API ${DEPENDENCY_DIR}/SDL-1.2.15/include/*.h)

file(GLOB_RECURSE GL3_HEADER ${DEPENDENCY_DIR}/GL3/*.h)
file(GLOB_RECURSE GL3_SOURCE ${DEPENDENCY_DIR}/GL3/*.cpp)
file(GLOB_RECURSE GL3_SOURCE_C ${DEPENDENCY_DIR}/GL3/*.c)

file(GLOB ROOT_HEADER *.h)
file(GLOB VIEWS_HEADER Views/*.h)
file(GLOB ROOT_SOURCE *.cpp)
file(GLOB VIEWS_SOURCE Views/*.cpp)

SOURCE_GROUP("Resource Files\\Views" FILES ${VIEWS_RESOURCE})

SOURCE_GROUP("Header Files\\Depends\\LibTCOD" FILES ${LIBTCOD_HEADER_H} ${LIBTCOD_HEADER})
SOURCE_GROUP("Source Files\\Depends\\LibTCOD" FILES ${LIBTCOD_SOURCE_C} ${LIBTCOD_SOURCE})

SOURCE_GROUP("Header Files\\Depends\\GL3" FILES ${GL3_HEADER})
SOURCE_GROUP("Source Files\\Depends\\GL3" FILES ${GL3_SOURCE} ${GL3_SOURCE_C})

SOURCE_GROUP("Header Files\\Depends\\Totem" FILES ${TOTEM_HEADER})
SOURCE_GROUP("Header Files\\Depends\\GLM" FILES ${GLM_HEADER})
SOURCE_GROUP("Header Files\\Depends\\ZLib" FILES ${ZLIB_HEADER})
SOURCE_GROUP("Header Files\\Depends\\LibPNG" FILES ${PNG_HEADER})
SOURCE_GROUP("Header Files\\Depends\\SDL" FILES ${SDL_HEADER_API})

SOURCE_GROUP("Header Files\\Views" FILES ${VIEWS_HEADER})
SOURCE_GROUP("Source Files\\Views" FILES ${VIEWS_SOURCE})

set(RESOURCES
	${VIEWS_RESOURCE}
)

set(HDRS
	${TOTEM_HEADER}
	${GLM_HEADER}
	${ZLIB_HEADER}
	${PNG_HEADER}
	${SDL_HEADER_API}
	${LIBTCOD_HEADER_H} 
	${LIBTCOD_HEADER}
	${GL3_HEADER}
	
	${VIEWS_HEADER}
	${ROOT_HEADER}
)

set(SRCS
	${LIBTCOD_SOURCE_C}
	${LIBTCOD_SOURCE}
	${GL3_SOURCE} 
	${GL3_SOURCE_C}
	
	${VIEWS_SOURCE}
	${ROOT_SOURCE}
)

add_executable(${NAME} ${RESOURCES} ${HDRS} ${SRCS})
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DLIBTCOD_EXPORTS)

include_directories(${DEPENDENCY_DIR}/zlib-1.2.7/src)
include_directories(${DEPENDENCY_DIR}/libpng-1.5.10/src)
include_directories(${DEPENDENCY_DIR}/SDL-1.2.15/include)
include_directories(${DEPENDENCY_DIR}/SDL-1.2.15/include/SDL)

find_package(OpenGL REQUIRED)

target_link_libraries(${NAME} ZLib LibPNG SDL ${OPENGL_LIBRARY})

IF(MSVC)
	# Since libtcod pulls in DLLs that use the release CRT, force the linker to never try to cross match CRTs
	set_property(TARGET ${NAME} PROPERTY LINK_FLAGS "/NODEFAULTLIB:MSVCRTD.lib ")
ENDIF()
